﻿using HarmonyLib;
using RimWorld;
using Verse;

namespace RimZombieGirl
{
    [HarmonyPatch(typeof(IncidentWorker), "CanFireNow")]
    public static class Patch_IncidentBlocker
    {
        public static bool Prefix(IncidentWorker __instance, ref bool __result, IncidentParms parms)
        {
            var map = parms.target as Map;
            if (map == null) return true;

            var comp = map.GetComponent<MapComponent_Curse>();
            if (comp != null && comp.currentCurseValue >= 500f)
            {
                // 允许袭击事件，不允许其他事件
                if (__instance.def.category == IncidentCategoryDefOf.ThreatBig ||
                    __instance.def.category == IncidentCategoryDefOf.ThreatSmall|| __instance.def.tags.Contains("RI_Cursed"))
                {
                    return true; // 允许
                }
                Log.Message("Curse level too high, blocking incident: " + __instance.def.defName);
                __result = false; // 阻止
                return false;
            }

            return true; // 正常执行
        }
    }
}
